﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using Tisbi.LawFirm.DAL.Models;

namespace Tisbi.LawFirm.BL.Services.Implementation.Mock
{
    // Add ServiceAgentExport attribute, setting AgentType to Mock

    public class MockCaseServiceAgent : MockServiceAgentBase<Cases>, ICaseServiceAgent
    {

        // Mock data
        List<Cases> mockCases;
        List<List<Lawsuits>> lawsuitses;
        List<Court> mockCourts;
        List<Employees> mockEmployees;
        List<District> mockDistricts;

        public MockCaseServiceAgent()
        {
            new MockEmployeeServiceAgent().GetItem(GetEmployeesCompleted);
            new MockCourtServiceAgent().GetItem(GetCourtCompleted);
            new MockDistrictServiceAgent().GetItem(GetDistrictCompleate);
           

            // Mock Court type
            CourtType arbitrationCourtType = new CourtType { Id = 1, CourtTypeTitle = "Арбитражный суд" };
            CourtType regularСourtType = new CourtType { Id = 1, CourtTypeTitle = "Арбитражный суд" };

            // Mock Lawsuitses
            lawsuitses = new List<List<Lawsuits>>
            {
                new List<Lawsuits>
                {
                    new Lawsuits
                    {
                        Id = 1,
                        IsActive = true,
                        FileLinkBytes = null,
                        Created = DateTime.Now,
                        Number = "123",
                        CourtType = arbitrationCourtType,
                        District = mockDistricts[0],
                        Plaintiff = new Customers{ Id = 1, FullFio = "Мухаметзянов Марат Радифлвич" },
                        Defendant = new Customers{ Id = 2, FullFio = "Баканов Андрей Сергеевич" },
                        ThirdParties = null,
                        StatementOfClaimType = new StatementOfClaimType{ Id = 1, StatementOfClaimTypeTitle = "об оспаривании ненормативного акта налогового органа" },
                        ContentRequirements = "Сожержание требований",
                        PrincipalDebt = 10000,
                        LatePaymentCharge = 0,
                        ClaimAmount = 10000,
                        NationalDuty = 1000,
                        Outcome = Outcome.НетРешения,
                        OutcomeAmount = 0,
                        Court = mockCourts[0],
                        CourtCaseNumber = "Дело номер 123",
                        ContactsOfJudge = "Пулмпянский Виктор Андреевич, телеофн: +79503524125",
                        HearingDate = null,
                        LocationCaseMaterials = null,
                        DateOfDecision = null,
                        ResultOfDecision = "Содержание решения",
                        Appeals = null
                    }
                }
            };

            // Init mock data
            mockCases = new List<Cases>
            {
                new Cases {Id = 1, Title = "Дело №1", Employees = mockEmployees[0], Created = DateTime.Now, Lawsuitses = lawsuitses[0] },
                new Cases {Id = 2, Title = "Дело №2", Employees = mockEmployees[0], Created = DateTime.Now.AddDays(-1)},
                new Cases {Id = 3, Title = "Дело №3", Employees = mockEmployees[1], Created = DateTime.Now.AddDays(-2)}
            };
        }

        private void GetDistrictCompleate(List<District> districts, Exception exception)
        {
            mockDistricts = districts;
        }


        private void GetCourtCompleted(List<Court> courts, Exception exception)
        {
            mockCourts = courts;
        }

        private void GetEmployeesCompleted(List<Employees> employeeses, Exception exception)
        {
            mockEmployees = employeeses;
        }

        public void GetCasesByEmployee(int employeeId, Action<List<Cases>, Exception> completed)
        {
            try
            {
                List<Cases> caseses = mockCases.Where(x => x.Employees.Id == employeeId).ToList();
                completed(caseses, null);
            }
            catch (Exception ex)
            {
                completed(null, ex);
            }
        }

        public override void GetItem(Action<List<Cases>, Exception> completed)
        {
            try
            {
                completed(mockCases, null);
            }
            catch (Exception ex)
            {
                completed(null, ex);
            }
        }

        public override void AddItem(Cases item, Action<Exception> completed)
        {
            mockCases.Add(item);
        }

        public override void RemoveItem(Cases item)
        {
            mockCases.Remove(item);
        }

        public override void Edit(Cases item, Action<Exception> completed)
        {
            MessageBox.Show("Edit not implemented");
        }
    }
}
